
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
-- --------------------------------------------------
-- Date Created: 10/29/2015 10:05:53
-- Generated from EDMX file: E:\Project\TimeTableOne\Model\TimeTable.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [TimeTable];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_系部班级]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[班级Set] DROP CONSTRAINT [FK_系部班级];
GO
IF OBJECT_ID(N'[dbo].[FK_学院系部]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[系部Set] DROP CONSTRAINT [FK_学院系部];
GO
IF OBJECT_ID(N'[dbo].[FK_系部教师]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[教师Set] DROP CONSTRAINT [FK_系部教师];
GO
IF OBJECT_ID(N'[dbo].[FK_班级用户]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[用户Set] DROP CONSTRAINT [FK_班级用户];
GO
IF OBJECT_ID(N'[dbo].[FK_教师课程]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[课程Set] DROP CONSTRAINT [FK_教师课程];
GO
IF OBJECT_ID(N'[dbo].[FK_班级课程]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[课程Set] DROP CONSTRAINT [FK_班级课程];
GO
IF OBJECT_ID(N'[dbo].[FK_用户课程]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[课程Set] DROP CONSTRAINT [FK_用户课程];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[教师Set]', 'U') IS NOT NULL
    DROP TABLE [dbo].[教师Set];
GO
IF OBJECT_ID(N'[dbo].[学院Set]', 'U') IS NOT NULL
    DROP TABLE [dbo].[学院Set];
GO
IF OBJECT_ID(N'[dbo].[班级Set]', 'U') IS NOT NULL
    DROP TABLE [dbo].[班级Set];
GO
IF OBJECT_ID(N'[dbo].[用户Set]', 'U') IS NOT NULL
    DROP TABLE [dbo].[用户Set];
GO
IF OBJECT_ID(N'[dbo].[系部Set]', 'U') IS NOT NULL
    DROP TABLE [dbo].[系部Set];
GO
IF OBJECT_ID(N'[dbo].[课程Set]', 'U') IS NOT NULL
    DROP TABLE [dbo].[课程Set];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table '教师Set'
CREATE TABLE [dbo].[教师Set] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [姓名] nvarchar(max)  NOT NULL,
    [工号] nvarchar(max)  NOT NULL,
    [电话号码] nvarchar(max)  NOT NULL,
    [系部Id] int  NOT NULL
);
GO

-- Creating table '学院Set'
CREATE TABLE [dbo].[学院Set] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [名称] nvarchar(max)  NOT NULL,
    [地址] nvarchar(max)  NOT NULL
);
GO

-- Creating table '班级Set'
CREATE TABLE [dbo].[班级Set] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [入学年份] smallint  NOT NULL,
    [名称] nvarchar(max)  NOT NULL,
    [系部Id] int  NOT NULL
);
GO

-- Creating table '用户Set'
CREATE TABLE [dbo].[用户Set] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [昵称] nvarchar(max)  NOT NULL,
    [手机号码] nvarchar(max)  NOT NULL,
    [密码] nvarchar(max)  NOT NULL,
    [班级Id] int  NULL,
    [课程Id] int  NULL
);
GO

-- Creating table '系部Set'
CREATE TABLE [dbo].[系部Set] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [系名] nvarchar(max)  NOT NULL,
    [学院Id] int  NOT NULL
);
GO

-- Creating table '课程Set'
CREATE TABLE [dbo].[课程Set] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [课程名] nvarchar(max)  NOT NULL,
    [课程类别] nvarchar(max)  NOT NULL,
    [周次] nvarchar(max)  NOT NULL,
    [节次] nvarchar(max)  NOT NULL,
    [地点] nvarchar(max)  NOT NULL,
    [学期] nvarchar(max)  NOT NULL,
    [教师Id] int  NOT NULL,
    [班级Id] int  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table '教师Set'
ALTER TABLE [dbo].[教师Set]
ADD CONSTRAINT [PK_教师Set]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table '学院Set'
ALTER TABLE [dbo].[学院Set]
ADD CONSTRAINT [PK_学院Set]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table '班级Set'
ALTER TABLE [dbo].[班级Set]
ADD CONSTRAINT [PK_班级Set]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table '用户Set'
ALTER TABLE [dbo].[用户Set]
ADD CONSTRAINT [PK_用户Set]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table '系部Set'
ALTER TABLE [dbo].[系部Set]
ADD CONSTRAINT [PK_系部Set]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table '课程Set'
ALTER TABLE [dbo].[课程Set]
ADD CONSTRAINT [PK_课程Set]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [系部Id] in table '班级Set'
ALTER TABLE [dbo].[班级Set]
ADD CONSTRAINT [FK_系部班级]
    FOREIGN KEY ([系部Id])
    REFERENCES [dbo].[系部Set]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_系部班级'
CREATE INDEX [IX_FK_系部班级]
ON [dbo].[班级Set]
    ([系部Id]);
GO

-- Creating foreign key on [学院Id] in table '系部Set'
ALTER TABLE [dbo].[系部Set]
ADD CONSTRAINT [FK_学院系部]
    FOREIGN KEY ([学院Id])
    REFERENCES [dbo].[学院Set]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_学院系部'
CREATE INDEX [IX_FK_学院系部]
ON [dbo].[系部Set]
    ([学院Id]);
GO

-- Creating foreign key on [系部Id] in table '教师Set'
ALTER TABLE [dbo].[教师Set]
ADD CONSTRAINT [FK_系部教师]
    FOREIGN KEY ([系部Id])
    REFERENCES [dbo].[系部Set]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_系部教师'
CREATE INDEX [IX_FK_系部教师]
ON [dbo].[教师Set]
    ([系部Id]);
GO

-- Creating foreign key on [班级Id] in table '用户Set'
ALTER TABLE [dbo].[用户Set]
ADD CONSTRAINT [FK_班级用户]
    FOREIGN KEY ([班级Id])
    REFERENCES [dbo].[班级Set]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_班级用户'
CREATE INDEX [IX_FK_班级用户]
ON [dbo].[用户Set]
    ([班级Id]);
GO

-- Creating foreign key on [教师Id] in table '课程Set'
ALTER TABLE [dbo].[课程Set]
ADD CONSTRAINT [FK_教师课程]
    FOREIGN KEY ([教师Id])
    REFERENCES [dbo].[教师Set]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_教师课程'
CREATE INDEX [IX_FK_教师课程]
ON [dbo].[课程Set]
    ([教师Id]);
GO

-- Creating foreign key on [班级Id] in table '课程Set'
ALTER TABLE [dbo].[课程Set]
ADD CONSTRAINT [FK_班级课程]
    FOREIGN KEY ([班级Id])
    REFERENCES [dbo].[班级Set]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_班级课程'
CREATE INDEX [IX_FK_班级课程]
ON [dbo].[课程Set]
    ([班级Id]);
GO

-- Creating foreign key on [课程Id] in table '用户Set'
ALTER TABLE [dbo].[用户Set]
ADD CONSTRAINT [FK_用户课程]
    FOREIGN KEY ([课程Id])
    REFERENCES [dbo].[课程Set]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_用户课程'
CREATE INDEX [IX_FK_用户课程]
ON [dbo].[用户Set]
    ([课程Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------